package ch.zbw.swt.sysventory.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;

import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;



import IMG.GetPath;

/*
 * Hauptmenü für Sysventory
 */

public class GUIMenu extends JFrame{

	//Panels
	
	private JPanel panel;
	
	//Bilder
	
	private ImageIcon goArrow;
	
	//Labels
	
	private JLabel menuTitelLabel;
	
	//Radio und Buttons
	
	private JButton go2actionButton;
	
	private JRadioButton scanRadioButton;
	private JRadioButton statRadioButton;
	private JRadioButton invRadioButton;
	
	private ButtonGroup groupMenuRadioButton;

	//Listener
	
	private Action action;
	
	/**
	 * Konstruktor von Menu
	 */
	
	public GUIMenu(Action action) {
		this.action = action;
	}

	/**
	 * /**
	 * initialisieren von Menu
	 */
	
	public void initialize(boolean isAdmin) {

		//Eingschaften der GUI
		
		this.getContentPane().setBackground(Color.WHITE);
		this.setBackground(Color.WHITE);
		this.setBounds(100, 100, 770, 480);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.getContentPane().setLayout(null);

		//Einmittung
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		int top = (screenSize.height - this.getHeight()) / 2;
		int left = (screenSize.width - this.getWidth()) / 2;
		
		//weiter Eigenschaften
		
		this.setLocation(left, top);
		this.setResizable(false);
		this.setVisible(true);

		//Einfügen der Elemente
		
		panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(10, 11, 744, 83);
		this.getContentPane().add(panel);
		panel.setLayout(null);

		goArrow = new ImageIcon(GetPath.class.getResource("go.png"));

		menuTitelLabel = new JLabel("Menu");
		menuTitelLabel.setFont(new Font("Impact", Font.PLAIN, 36));
		menuTitelLabel.setBounds(322, 11, 209, 61);
		panel.add(menuTitelLabel);

		go2actionButton = new JButton(goArrow);
				
		go2actionButton.setBackground(Color.WHITE);
		go2actionButton.setBounds(592, 11, 129, 61);
		go2actionButton.setBorder(null);
		panel.add(go2actionButton);
		
		scanRadioButton = new JRadioButton("Scannen");
		scanRadioButton.setFont(new Font("Impact", Font.PLAIN, 16));
		scanRadioButton.setBackground(Color.WHITE);
		scanRadioButton.setBounds(332, 176, 274, 45);
		
		this.getContentPane().add(scanRadioButton);

		// ScanRadioButton wird nur angezeigt wenn User Inventor ist
		
		if (isAdmin == false){
			scanRadioButton.setVisible(false);
		}

		statRadioButton = new JRadioButton("Statistik");
		statRadioButton.setFont(new Font("Impact", Font.PLAIN, 16));
		statRadioButton.setBackground(Color.WHITE);
		statRadioButton.setBounds(332, 272, 274, 45);
		this.getContentPane().add(statRadioButton);

		invRadioButton = new JRadioButton("Inventurdaten suchen");
		invRadioButton.setFont(new Font("Impact", Font.PLAIN, 16));
		invRadioButton.setBackground(Color.WHITE);
		invRadioButton.setBounds(332, 224, 274, 45);
		this.getContentPane().add(invRadioButton);
		
		groupMenuRadioButton = new ButtonGroup();
		groupMenuRadioButton.add(scanRadioButton);
		groupMenuRadioButton.add(statRadioButton);
		groupMenuRadioButton.add(invRadioButton);
		
		//Listener hinzufügen
		
		go2actionButton.addActionListener(action);
		go2actionButton.setActionCommand("go2action");

		
	}

	
	/*
	 * Liefert den ausgewählen Radiobutton zurück bei keiner Auswahl
	 * wird 0 als Fehler zurückgeliefert.
	 */
	
	public int getAuswahl() {
		if (scanRadioButton.isSelected()){
			return 1;
		}
		if (invRadioButton.isSelected()){
			return 2;
		}
		if (statRadioButton.isSelected()){
			return 3;
		}
		return 0;
	}
}
